package cii_lib_graph.elements;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import resources.UltimateOPS;
import testy.TestHardware;
import cii_lib.CCII_ACCESS_INTERF;
import cii_opto.CCII_MUX_DATA_TRANSCEIVER;
import cii_opto.CII_OPTO_cfg_tab;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SelectCIIUnit extends javax.swing.JDialog {
	
	private static final Logger log = LoggerFactory
			.getLogger(SelectCIIUnit.class);

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			log.error("", e);
		}
	}

	private JScrollPane jScrollPane1;
	private JButton jButton1;
	private JButton accapetB;
	private JButton Add;
	private JTree jTree1;

	private CCII_ACCESS_INTERF interfac ;
	CCII_MUX_DATA_TRANSCEIVER glob;
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				SelectCIIUnit inst = new SelectCIIUnit();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public SelectCIIUnit() {
		super();
		initGUI();
	}
	
	public SelectCIIUnit(JFrame frame, String title, boolean mode) {
		super(frame, title, mode);
		initGUI();
		
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			
			{
				jScrollPane1 = new JScrollPane();
				getContentPane().add(jScrollPane1);
				jScrollPane1.setBounds(0, 0, 284, 286);
				{
					jTree1 = new JTree();
					jScrollPane1.setViewportView(jTree1);
					//
					glob = new CCII_MUX_DATA_TRANSCEIVER(CII_OPTO_cfg_tab.ITAB,0,new TestHardware(),null);
					DefaultMutableTreeNode aa = new DefaultMutableTreeNode();
					aa= UltimateOPS.buildTreeModel(glob.CII_MUX_DATA_TRANSCEIVER());
					DefaultTreeModel dm = new DefaultTreeModel(aa);
					jTree1.setCellRenderer(UltimateOPS.treeRenderer());
					jTree1.setModel(dm);
				}
			}
			{
				Add = new JButton();
				getContentPane().add(Add);
				Add.setText("Add");
				Add.setBounds(293, 12, 55, 21);
			}
			{
				accapetB = new JButton();
				getContentPane().add(accapetB);
				accapetB.setText("Ok");
				accapetB.setBounds(293, 230, 55, 21);
				accapetB.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) { log.info("Command: {}", evt.getActionCommand());
						setInterface(glob.BITS_TEST());
						close();
					}
				});
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Cancel");
				jButton1.setBounds(293, 256, 55, 21);
				jButton1.setOpaque(false);
				jButton1.setMargin(new java.awt.Insets(1, 1, 1, 1));
			}
			pack();
			this.setSize(367, 315);
			this.setLocation(UltimateOPS.centerLocation(367, 315));
		} catch (Exception e) {
			log.error("", e);
		}
	}
	
	public CCII_ACCESS_INTERF getInterface() {
		return interfac;
	}
	
	public void setInterface(CCII_ACCESS_INTERF c) {
		interfac = c;
	}

	private void close() {
		dispose();
	}
}
